// #ifdef MP-WEIXIN
const baseUrl = 'http://localhost';
// #endif
// #ifdef H5
const baseUrl = '/api';
// #endif
const json2url = (json) => {
  let arr = [];
  for (let key in json) {
    arr.push(key + '=' + json[key])
  }
  return arr.join('&')
}
const http = (options) => {
  if (!options.url) {
    console.log('地址为空');
    return;
  }
  let method = options.method || 'get';
  let data = options.data || {};
  let params = options.params || {};
  let json = {
    url: baseUrl + options.url + '?' + json2url(params),
    method,
    data
  }
  console.log(json.url);
  if (options.success) {
    json.success = options.success
  }
  if (options.fail) {
    json.fail = options.fail
  }
  uni.request(json)
}

export default http;
